import { SET_USER, CLEAR_USER } from '../actions/types';

interface AuthState {
    user: string | null;
    token: string | null;
}

const initialState: AuthState = {
    user: null,
    token: null
};
interface Action {
    type: string;
    payload?: any;
}
const authReducer = (state: AuthState = initialState, action: Action) => {
    switch (action.type) {
        case SET_USER:
            return {
              ...state,
                user: action.payload.user,
                token: action.payload.token
            };
        case CLEAR_USER:
            return initialState;
        default:
            return state;
    }
};

export default authReducer;